package com.walle.activityservice.service.impl;

import com.walle.activityservice.dao.BusinessDefineDao;
import com.walle.activityservice.model.BusinessDefine;
import com.walle.activityservice.service.BusinessDefineService;
import com.walle.common.page.PageBean;
import com.walle.common.page.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangjiapeng
 * @Package com.hdai.dps.service.impl
 * @Description: ${todo}
 * @date 2018/12/19 11:24
 */
@Service
public class BusinessServiceDefineImpl implements BusinessDefineService {


    @Autowired
    private BusinessDefineDao businessDefineDao;

    /**
     * 添加
     *
     * @param businessDefine
     */
    @Override
    public void insert(BusinessDefine businessDefine) {
        businessDefineDao.insert(businessDefine);
    }

    /**
     * 更新
     *
     * @param businessDefine
     */
    @Override
    public void update(BusinessDefine businessDefine) {
        businessDefineDao.update(businessDefine);
    }

    /**
     * 根据ID获取
     *
     * @param businessId
     * @return
     */
    @Override
    public BusinessDefine getById(Long businessId) {
        return businessDefineDao.getById(businessId);
    }

    /**
     * 分页查询
     *
     * @param pageParam
     * @param businessDefine
     * @param sortColumnName
     * @param sortType
     * @return
     */
    @Override
    public PageBean<BusinessDefine> queryPage(PageParam pageParam, BusinessDefine businessDefine, String sortColumnName, String sortType) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("startRow", pageParam.getStartRow());
        paramMap.put("pageSize", pageParam.getNumPerPage());

        List<BusinessDefine> list = businessDefineDao.listPage(paramMap);
        Long count =  businessDefineDao.listPageCount(paramMap);
        return new PageBean<>(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list);
    }

    /**
     * 根据代码获取
     *
     * @param businessCode
     * @return
     */
    @Override
    public BusinessDefine getByCode(String businessCode) {
        return businessDefineDao.getByCode(businessCode);
    }

}
